from numpy import ravel
from sklearn import svm
from data import loadDataFromMat
import time

def runSVM(dataName='banana'):
    data=loadDataFromMat(dataName)
    X = data[0]
    y = ravel(data[1])
    num = y.shape[0]
    trainnum = num // 10 * 8
    start = time.clock()
    clf = svm.SVC()
    # y2=clf.predict(X)
    clf.fit(X[:trainnum], y[:trainnum])
    s=clf.score(X,y)
    end = time.clock()
    return end - start,(1-s)*100

# print('svm',end=',')
# runtimes=[]
# for dataname in ['banana', 'breast_cancer', 'diabetis', 'flare_solar', 'german', 'heart', 'image', 'ringnorm', 'splice', 'thyroid',
#      'titanic', 'twonorm', 'waveform']:
#     runtime,_=runSVM(dataname)
#     runtimes.append(runtime)
# print()
# for runtime in runtimes:
#     print(runtime,end=',')